<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>消息弹出</title>
    <style>
      button {
        font-family: cursive;
        font-size: 17px;
        width: 60px;
        border-radius: 50%;
        height: 60px;
        border: none;
        color: blue;
        background: aquamarine;
        box-shadow: 4px 4px grey;
        cursor: pointer;
      }
      body > div {
        text-align: center;
        /* margin-top: 100px; */
      }
      button:active {
        box-shadow: 1px 1px grey;
        transform: translateY(2px);
      }
      #snackbar {
        display: none;
        animation: zx 3s;
        position: absolute;
        width: 200px;
        height: 50px;
        line-height: 50px;
        background: black;
        color: #ffffff;
        left: 40%;
        /* bottom: 0; */
        top: -55px;
      }
      .top {
        padding-top: 100px;
      }
      @keyframes zx {
        0% {
          opacity: 0;
          top: -55px;
        }
        100% {
          opacity: 1;
          top: 200px;
        }
      }
    </style>
  </head>
  <body>
    <div class="top">
      <button onclick="myFunction()">显示</button>
    </div>

    <div id="snackbar">一些文本..</div>
    <script>
      let text = document.getElementById("snackbar");
      function myFunction() {
        text.style.display = "block";
        setTimeout(() => {
          text.style.display = "";
        }, 3000);
      }
    </script>
  </body>
</html>
